<div id="publishUrlListGrid"></div>
<script>
    $(function(){
    	var script = document.createElement('script');
        script.src = contextPath + '/js/jbpmDesigner/publishUrlList.js';
        document.getElementById('publishUrlListGrid').parentNode.appendChild(script);
        var columns = [
            {
                title : '名称',
                name : 'name',
                width : 200
            },
            {
                title : 'URL',
                name : 'url',
                width : 450
            },
            {
                title : '操作',
                name : 'URL',
                width : 150,
                render: function(item, name, index){
                    return '<a onclick="publishUrlList.view(\''+item.name+'\',\''+item.url+'\')"><span class="glyphicon glyphicon-link"></span>&nbsp;查看</a>';
                }
            },
            {
                title : "浏览",
                name : 'URL',
                width : 150,
                render: function(item, name, index){
                    return '<a onclick="publishUrlList.browse(\''+item.id+'\')"><span class="glyphicon glyphicon-link"></span>&nbsp;浏览</a>';
                }
            }
        ];
        var querys = [
            {title: '名称', value: 'publishURLVO.name'},
            {title: 'URL', value: 'publishURLVO.url'}
        ];
        var buttons = [
            {content: '<button class="btn btn-primary" type="button"><span class="glyphicon glyphicon-plus"></span>&nbsp;新增</button>', action: 'add'},
            {content: '<button class="btn btn-success" type="button"><span class="glyphicon glyphicon-edit"></span>&nbsp;修改</button>', action: 'modify'},
            {content: '<button class="btn btn-danger" type="button"><span class="glyphicon glyphicon-remove"></span>&nbsp;删除</button>', action: 'delete'}
        ];
        $('#publishUrlListGrid').grid({
            identity: 'id',
            columns: columns,
            buttons: buttons,
            querys: querys,
            url: 'core-PublishURL-pageJson.action'
        }).on({
                    'add': function(){
                        publishUrlList.add( $(this));
                    },
                    'modify': function(event, data){
                        var items = data.item;
                        var $this = $(this);
                        if(items.length == 0){
                            $this.message({
                                type: 'warning',
                                content: '请选择一条记录进行修改'
                            })
                            return;
                        }
                        if(items.length > 1){
                            $this.message({
                                type: 'warning',
                                content: '只能选择一条记录进行修改'
                            })
                            return;
                        }
                        publishUrlList.modify(items[0], $this);
                    },
                    'delete': function(event, data){
                        var indexs = data.data;
                        var $this = $(this)
                        if(indexs.length == 0){
                            $this.message({
                                type: 'warning',
                                content: '请选择要删除的记录'
                            })
                            return;
                        }
                        $this.confirm({
                            content: '确定要删除所选记录吗?',
                            callBack: function(){ publishUrlList.delete(indexs, $this);}
                        });
                    }
                })
    });
</script>